home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 53 / IOPROG_53.ISO / soft / c++ / xceedbkp.exe / Recovery Wizard / Sources / clsXceed.cls < prev    next >
Encoding:
Visual Basic class definition  |  1999-09-02  |  10.7 KB  |  329 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsXceed"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Public WithEvents xMain As XceedBackup
  17. Attribute xMain.VB_VarHelpID = -1
  18.  
  19. Public xRestore As RestoreJob
  20. Public xSelection As FileSelection
  21. Public PositionTop As Long
  22. Public PositionLeft As Long
  23. Public BackupFolder As String
  24. Public ReplaceAll As VbMsgBoxResult
  25.  
  26. ' Remember file selection
  27. Private saSelectedFiles() As String
  28. Private lSelectedFiles As Long
  29. Private saSelectedKeys() As String
  30. Private lSelectedKeys As Long
  31.  
  32. Private WithEvents xStatus As frmStatus
  33. Attribute xStatus.VB_VarHelpID = -1
  34. Private xMessage As frmMessage
  35. Attribute xMessage.VB_VarHelpID = -1
  36.  
  37. '
  38. ' Properties
  39. '
  40. Property Get SelectedFiles(lIndex As Long) As String
  41.     If lIndex < 0 Or lIndex >= lSelectedFiles Then
  42.         SelectedFiles = ""
  43.     Else
  44.         SelectedFiles = saSelectedFiles(lIndex)
  45.     End If
  46. End Property
  47.  
  48. Public Sub AddSelectedFiles(sFile As String)
  49.     If lSelectedFiles <= UBound(saSelectedFiles) Then
  50.         saSelectedFiles(lSelectedFiles) = sFile
  51.         lSelectedFiles = lSelectedFiles + 1
  52.     End If
  53. End Sub
  54.  
  55. Property Let MaxSelectedFiles(lSize As Long)
  56.     If lSize > 0 Then
  57.         ReDim saSelectedFiles(0 To lSize - 1)
  58.     End If
  59.     lSelectedFiles = 0
  60. End Property
  61.  
  62. Property Get SelectedFilesCount() As Long
  63.     SelectedFilesCount = lSelectedFiles
  64. End Property
  65.  
  66. Property Get SelectedKeys(lIndex As Long) As String
  67.     If lIndex < 0 Or lIndex >= lSelectedKeys Then
  68.         SelectedKeys = ""
  69.     Else
  70.         SelectedKeys = saSelectedKeys(lIndex)
  71.     End If
  72. End Property
  73.  
  74. Public Sub AddSelectedKeys(sKey As String)
  75.     If lSelectedKeys <= UBound(saSelectedKeys) Then
  76.         saSelectedKeys(lSelectedKeys) = sKey
  77.         lSelectedKeys = lSelectedKeys + 1
  78.     End If
  79. End Sub
  80.  
  81. Property Let MaxSelectedKeys(lSize As Long)
  82.     If lSize > 0 Then
  83.         ReDim saSelectedKeys(0 To lSize - 1)
  84.     End If
  85.     lSelectedKeys = 0
  86. End Property
  87.  
  88. Property Get SelectedKeysCount() As Long
  89.     SelectedKeysCount = lSelectedKeys
  90. End Property
  91.  
  92. '
  93. ' Methods
  94. '
  95. Private Sub Class_Initialize()
  96.     
  97.     'Intialize all the objects that will be used
  98.     
  99.     Set xMain = New XceedBackup
  100.     Set xRestore = New RestoreJob
  101.     Set xSelection = New FileSelection
  102.     Set xStatus = New frmStatus
  103.     Set xMessage = New frmMessage
  104.     ReplaceAll = vbCancel
  105.     
  106.     lSelectedFiles = 0
  107.     lSelectedKeys = 0
  108.     
  109. End Sub
  110.  
  111. Private Sub Class_Terminate()
  112.  
  113.     'Release all the objects
  114.        
  115.     Set xMain = Nothing
  116.     Set xRestore = Nothing
  117.     Set xSelection = Nothing
  118.     Unload xStatus
  119.     Set xStatus = Nothing
  120.     Unload xMessage
  121.     Set xMessage = Nothing
  122.     Unload frmHidden
  123.     
  124. End Sub
  125.  
  126. Private Sub xMain_BeforeRestoringFile(ByVal sFilename As String, ByVal lSize As Long, ByVal xAttributes As XceedBackupLib.bkpFileAttributes, ByVal dtLastModified As Date, ByVal dtLastAccessed As Date, ByVal dtCreated As Date, ByVal lDiskNumber As Long)
  127.  
  128.     xStatus.lblFileName.Caption = sFilename & "   Size: " & lSize
  129.   
  130. End Sub
  131.  
  132. Private Sub xMain_FileStatus(ByVal sFilename As String, ByVal lSize As Long, ByVal lBytesProcessed As Long, ByVal nPercentCompleted As Integer)
  133.  
  134.     xStatus.lblFileName.Caption = sFilename
  135.     xStatus.ItemPercent = nPercentCompleted
  136.    
  137. End Sub
  138.  
  139. Private Sub xMain_GlobalStatus(ByVal lFilesTotal As Long, ByVal lFilesProcessed As Long, ByVal lFilesSkipped As Long, ByVal nFilesPercent As Integer, ByVal lBytesTotal As Long, ByVal lBytesProcessed As Long, ByVal lBytesSkipped As Long, ByVal nBytesPercent As Integer)
  140.     
  141.     If xMain.CurrentOperation = bcoRecreateCatalogs Then
  142.         frmTwo.Percent = nFilesPercent
  143.     Else
  144.         xStatus.TotalPercent = nBytesPercent
  145.         xStatus.lblPercent.Caption = nBytesPercent & "%"
  146.     End If
  147.     
  148. End Sub
  149.  
  150. Private Sub xMain_InsertMedia(ByVal sMediaLabel As String, ByVal lDiskNumber As Long, bMediaInserted As Boolean)
  151.  
  152.     Dim Answer As VbMsgBoxResult
  153.  
  154.     Answer = MsgBox("Please insert disk number " & Trim(Str(lDiskNumber)) & " of the media labeled """ & sMediaLabel & """", _
  155.                     vbOKCancel + vbInformation)
  156.                     
  157.     If Answer = vbOK Then
  158.         bMediaInserted = True
  159.     End If
  160.     
  161. End Sub
  162.  
  163. Public Function RecreateCatalogs() As Boolean
  164.  
  165.     Dim ResultCode As bkpError
  166.     Dim Answer As VbMsgBoxResult
  167.  
  168.     'Confirm if the catalogs are to be recreated
  169.     
  170.     Answer = MsgBox("You are about to recreate the catalogs. Do you want to continue?", _
  171.                     vbYesNo + vbQuestion)
  172.     
  173.     'If cancel is pressed then the backups are not recreated
  174.     
  175.     RecreateCatalogs = False
  176.     
  177.     'If OK is pressed then recreate the catalogs
  178.     
  179.     If Answer = vbYes Then
  180.         ResultCode = xMain.RecreateCatalogs(xRestore.BackupSetName, BackupFolder)
  181.         If ResultCode = berSuccess Then
  182.             MsgBox "Catalogs have been successfully recreated.", vbOKOnly + vbExclamation
  183.             RecreateCatalogs = True
  184.         Else
  185.             MsgBox "Could not recreate the catalogs. Error code " & Trim(Str(ResultCode)) & " (" & xMain.GetErrorDescription(bvtError, ResultCode) & ")", _
  186.                    vbOKOnly + vbCritical
  187.         End If
  188.     End If
  189.  
  190. End Function
  191.  
  192. Private Sub xMain_InvalidPassword(ByVal sBackupFilename As String, sPassword As String, bPasswordProvided As Boolean)
  193.  
  194.     'Triggered if an invalid password was given
  195.     
  196.     sPassword = InputBox("The password you have provided for the backup set " & sBackupFilename & " is invalid. Please enter a new one.", "Recovery Wizard")
  197.     
  198.     'If cancel is pressed, the input box returns an empty string.
  199.     'If a valid password is entered then set bPasswordProvided to True
  200.     'If an invalid password is provided, it will again trigger the
  201.     'InvalidPassword event
  202.     
  203.     If sPassword = "" Then
  204.         bPasswordProvided = False
  205.     Else
  206.         bPasswordProvided = True
  207.     End If
  208.  
  209. End Sub
  210.  
  211. Private Sub xMain_ProcessCompleted(ByVal lFilesTotal As Long, ByVal lFilesProcessed As Long, ByVal lFilesSkipped As Long, ByVal lBytesTotal As Long, ByVal lBytesProcessed As Long, ByVal lBytesSkipped As Long, ByVal xResult As XceedBackupLib.bkpError)
  212.  
  213.     If xMain.CurrentOperation = bcoManualRestore Then
  214.         xStatus.lstSkipped.AddItem ("==============================")
  215.         xStatus.lstSkipped.AddItem ("Total number of files : " & lFilesTotal)
  216.         xStatus.lstSkipped.AddItem ("Files processed : " & lFilesProcessed)
  217.         xStatus.lstSkipped.AddItem ("Files Skipped : " & lFilesSkipped)
  218.         xStatus.lstSkipped.AddItem ("===============================")
  219.         xStatus.lstSkipped.AddItem ("Result : " & xResult & " - " & xMain.GetErrorDescription(bvtError, xResult))
  220.     End If
  221.     
  222. End Sub
  223.  
  224. Private Sub xMain_ReplacingFile(ByVal sFilename As String, ByVal lExistingSize As Long, ByVal xExistingAttributes As XceedBackupLib.bkpFileAttributes, ByVal dtExistingLastModified As Date, ByVal dtExistingLastAccessed As Date, ByVal dtExistingCreated As Date, ByVal lSize As Long, ByVal xAttributes As XceedBackupLib.bkpFileAttributes, ByVal dtLastModified As Date, ByVal dtLastAccessed As Date, ByVal dtCreated As Date, ByVal lDiskNumber As Long, bSkipFile As Boolean)
  225.     
  226.     Dim Answer As VbMsgBoxResult
  227.     
  228.     'ReplaceAll is used to avoid asking for each file to replace
  229.     If ReplaceAll = vbCancel Then
  230.         ReplaceAll = MsgBox("At least one file being restored already exists. Do you want to replace all the files?", _
  231.                             vbYesNo + vbQuestion)
  232.     End If
  233.     
  234.     If ReplaceAll = vbYes Then
  235.         bSkipFile = False
  236.     Else
  237.         Answer = MsgBox("Do you wish to replace " & sFilename & " ?", vbYesNo + vbQuestion)
  238.         If Answer = vbYes Then
  239.             bSkipFile = False
  240.         End If
  241.     End If
  242.    
  243. End Sub
  244.  
  245. Private Sub xMain_ReplacingRegKey(ByVal sRegKey As String, xAction As XceedBackupLib.bkpReplacingRegKeyAction)
  246.  
  247.     Dim xActionMessage As enuActionMessage
  248.     
  249.     xMessage.lblRegKey = sRegKey
  250.     'ShowForm from frmMessage returns enuActionMessage which will determine wether
  251.     'the Registry keys will be Skipped, Merged or Overwritten. And if it is applied to all
  252.     
  253.     xActionMessage = xMessage.ShowForm
  254.     
  255.     If xActionMessage <> maAbort Then
  256.         xAction = xActionMessage
  257.     Else
  258.         xMain.Abort = True
  259.     End If
  260.  
  261. End Sub
  262.  
  263. Private Sub xMain_RestoringRegKey(ByVal sRegKey As String)
  264.  
  265.     xMessage.lblRegKey.Caption = sRegKey
  266.     
  267. End Sub
  268.  
  269. Private Sub xMain_SkippingFile(ByVal sFilename As String, ByVal lSize As Long, ByVal xAttributes As XceedBackupLib.bkpFileAttributes, ByVal dtLastModified As Date, ByVal dtLastAccessed As Date, ByVal dtCreated As Date, ByVal xSkippingReason As XceedBackupLib.bkpSkippingReason)
  270.  
  271.     xStatus.lstSkipped.AddItem (sFilename & "   Reason : " & xSkippingReason & " " & xMain.GetErrorDescription(bvtSkippingReason, xSkippingReason))
  272.         
  273. End Sub
  274.  
  275. Private Sub xMain_SkippingRegKey(ByVal sRegKey As String, ByVal xSkippingReason As XceedBackupLib.bkpSkippingReason)
  276.  
  277.     xStatus.lstSkipped.AddItem (sRegKey & "   Reason : " & xSkippingReason & " " & xMain.GetErrorDescription(bvtSkippingReason, xSkippingReason))
  278.     
  279. End Sub
  280.  
  281. Public Function RestoreBackup() As Boolean
  282.  
  283.     ReplaceAll = vbCancel
  284.     xStatus.ShowForm
  285.  
  286. End Function
  287.  
  288. Private Sub xStatus_Cancel()
  289.     
  290.     If MsgBox("Are you sure you want to abort the restoration?", vbYesNo + vbQuestion) = vbYes Then
  291.         xMain.Abort = True
  292.     End If
  293.     
  294. End Sub
  295.  
  296. Private Sub xStatus_StartRestore()
  297.  
  298.     Dim ResultCode As bkpError
  299.             
  300.     ' Fill the FilesToProcess and RegKeysToInclude
  301.     Dim i As Integer
  302.     
  303.     xSelection.FilesToProcess = ""
  304.     For i = 0 To lSelectedFiles - 1
  305.         xSelection.AddFilesToProcess saSelectedFiles(i), False
  306.     Next i
  307.     
  308.     xSelection.RegKeysToInclude = ""
  309.     For i = 0 To lSelectedKeys - 1
  310.         xSelection.AddRegKeysToInclude saSelectedKeys(i)
  311.     Next i
  312.     
  313.     'The file selection is passed to xRestore and the restoration of the backups can start
  314.     
  315.     xRestore.Selection = xSelection
  316.     ResultCode = xMain.Restore(xRestore)
  317.     
  318.     'Checks the return code
  319.     
  320.     If ResultCode = 0 Then
  321.         MsgBox "All files have been successfully restored.", vbOKOnly + vbExclamation
  322.     Else
  323.         MsgBox "Restore failed. Error code " & Trim(Str(ResultCode)) & " (" & xMain.GetErrorDescription(bvtError, ResultCode) & ")", _
  324.                vbOKOnly + vbCritical
  325.     End If
  326.              
  327. End Sub
  328.  
  329.